package top.greatxiaozou.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.greatxiaozou.dto.DtoUser;
import top.greatxiaozou.mapper.UserMapper;
import top.greatxiaozou.pojo.User;
import top.greatxiaozou.service.UserService;
import top.greatxiaozou.utils.UserUtils;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public int registUser(DtoUser user) {
        if (userMapper.selectUserByName(user.getUsername())!=null){
            return -1;
        }
        User realUser = UserUtils.changeUser(user);
        return userMapper.registUser(realUser);
    }

    @Override
    public User selectUserByName(String username) {
        User user = userMapper.selectUserByName(username);
        return user;
    }

    @Override
    public int updateUser(User user, String oldName) {
        return userMapper.updateUser(user, oldName);
    }
}
